<template>
	<view>
		<u-loading-page loading-text="加载中..." :loading="loading" bg-color="#fff"></u-loading-page>
		<u-navbar :title="$t('subscribe.titleText')" placeholder	 :autoBack="true" />
		<view class="content" v-if="!loading">
			<view class="box m-bottom-15">
				<view>
					<u--text :text="language=='zh'?detail.shopname:detail.shopname_copy?detail.shopname_copy:detail.shopname" bold size="19" lines="2" color="#000" margin="0 0 10px 0"></u--text>
					<u--text :text="timewhole(detail.reserve_time)" size="14" color="#989898" margin="0 0 10px 0" />
					<view class="flex from" v-if="detail.is_box == '1'">
						<text>{{$t('subscribe.deskNum')}}</text>
						<text class="mark">{{detail.num}}号</text>
					</view>
					<view class="flex from" v-if="detail.is_box == '0'">
						<text>包厢</text>
						<text class="mark">{{language == 'zh' ? detail.room_name : detail.room_name_copy}}</text>
					</view>
				</view>
				<u--image :src="detail.shop_avatar" width="100%" height="250rpx" radius="10px"></u--image>
			</view>
			<view class="code_box m-bottom-15">
				<view class="code flex">
					<view>{{$t('subscribe.digitCode')}}</view>
					<view class="code_num">{{detail.write_code}}</view>
				</view>
				<image :src="detail.write_code_image" class="code_image"></image>
				<u--text :text="$t('subscribe.writeoffCode')" align="center" color="#818181" size="15"></u--text>
			</view>
			<view class="info m-bottom-15">
				<view class="info_item">
					<text class="item_left">{{$t('subscribe.bookOrder')}}</text>
					<text class="item_right">{{detail.order_no}}</text>
				</view>
				<view class="info_item">
					<text class="item_left">{{$t('subscribe.bookPerson')}}</text>
					<text class="item_right">{{detail.reserve_people}}</text>
				</view>
				<view class="info_item">
					<text class="item_left">{{$t('subscribe.contactWay')}}</text>
					<text class="item_right">{{detail.reserve_mobile}}</text>
				</view>
				<view class="info_item">
					<text class="item_left">{{$t('subscribe.reserveTime')}}</text>
					<text class="item_right">{{timewhole(detail.reserve_time)}}</text>
				</view>
				<view class="info_item" v-if="detail.is_box == '1'">
					<text class="item_left">{{$t('subscribe.deskNum')}}</text>
					<text class="item_right">{{detail.num}}号</text>
				</view>
				<view class="info_item" v-if="detail.is_box == '0'">
					<text class="item_left">包厢</text>
					<text class="item_right">{{language == 'zh' ? detail.room_name : detail.room_name_copy}}</text>
				</view>
				<view class="info_item">
					<text class="item_left">{{$t('subscribe.eatNum')}}</text>
					<text class="item_right">{{detail.people_num}}</text>
				</view>
			</view>
			<view class="address">
				<text class="item_left">{{$t('subscribe.roomAddress')}}</text>
				<u--text :text="detail.address" color="#434343" size="15"></u--text>
			</view>
			<view class="menu m-top-15" v-if="type==1">
				<u--text :text="$t('subscribe.menuTitle')" size="18" bold margin="0 0 20px 0" color="#141414"></u--text>
				<view class="menu-list m-bottom-15">
					<view class="menu_item" v-for="(item,index) in order" :key="index">
						<image :src="item.image" mode="scaleToFill"></image>
						<u--text :text="item.title" color="#231916" size="15" lines="1"></u--text>
						<text class="num">X{{item.number||0}}</text>
						<text class="current">￥{{item.price}}</text>
					</view>
				</view>
			</view>
			<view class="footer">
				<view class="btn1" v-if="type==0">
					<u-button :text="$t('subscribe.cancelBtn')" v-if="state != 2" shape="circle" :customStyle="btn1Style" @click="show=true"></u-button>
					<u-button :text="$t('subscribe.advancedBtn')" shape="circle" :customStyle="btn2Style" @click="waitress"></u-button>
				</view>
				<view class="btn2" v-if="type==1 && state != 2" @click="show=true">{{$t('subscribe.cancelBtn')}}</view>
				<view class="safe_height_bottom"></view>
			</view>
		</view>
		<popup :title="$t('subscribe.popupTitle')" v-model="show">
			<view slot="center" class="center">
				<u--text :text="cancelDetail.message" color="#7C7C7C" size="15" lineHeight="30"></u--text>
				<view class="cancel-price">
					<text class="left">退款金额：</text>
					<text class="right">￥{{cancelDetail.price}}</text>
				</view>
				<u-button :text="$t('subscribe.popupBtn')" :customStyle="btn3Style" shape="circle" @click="onCancel"></u-button>
				<u--text :text="$t('subscribe.popupBtn1')" color="#FF9F04" size="16" align="center" margin="0 0 20px 0" @click="show=false" />
			</view>
		</popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: true,
				shop_id: 0,
				detail: {},
				btn1Style: {
					background: "#fff6db",
					border: "1px solid #FFBF00",
					color: "#000",
					height: "90rpx"
				},
				btn2Style: {
					background: "#FFC100",
					border: "none",
					color: "#000",
					height: "90rpx",
					margin:"0px 0px 0px 10px"
				},
				show: false,
				btn3Style: {
					background: "#FFC100",
					border: "none",
					color: "#000",
					height: "80rpx",
					width: "350rpx",
					margin: "20px auto"
				},
				type: undefined,
				cancelDetail: {},
				order: [],
				state:0
			};
		},
		computed: {
			language() {
				return this._i18n.locale
			}
		},
		onLoad(e) {
			this.shop_id = e.id
			this.init()
		},
		methods: {
			init() {
				this.$http.post('wanlshop/reserve/reserveDetail', {
					id: this.shop_id
				}).then(res => {
					if (res.code == 1) {
						this.loading = false
						this.type = res.data.type
						this.state = res.data.list.state
						this.detail = res.data.list
						if (this.type == 1) {
							this.order = res.data.order.orderGoods
						}
					}
				})
				this.$http.post('wanlshop/reserve/userMessage', {
					id: this.shop_id
				}).then(res => {
					if (res.code == 1) {
						this.cancelDetail = res.data
					}
				})
			},
			onCancel() {
				uni.showLoading({
					title: "加载中...",
					mask:true
				})
				this.$http.post('wanlshop/reserve/cancelReserve', {
					id: this.shop_id
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.show = false
						setTimeout(() => {
							uni.$emit("upList")
							this.$refs.uToast.show({
								type: "default",
								message: "取消成功",
								duration: 1000,
								complete() {
									uni.switchTab({
										url: "/pages/subscribe/index"
									})
								}
							})
						}, 300)
					}
				})
			},
			waitress() {
				uni.$u.route({
					url: '/pagesA/home/menuList',
					params: {
						shop_id: this.detail.shop_id,
						reserve_id: this.shop_id
					}
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f7f9;
	}
</style>
<style lang="scss" scoped>
	.center {
		margin: 36rpx 0 58rpx;
		padding: 0 38rpx;

		.cancel-price {
			margin: 20rpx 0;

			.left {
				color: #7C7C7C;
				size: 30rpx;
			}

			.right {
				margin-left: 10rpx;
				font-size: 30rpx;
				color: #FC4A31;
			}
		}
	}

	.content {
		padding: 30rpx 30rpx 200rpx 30rpx;

		.box {
			padding: 40rpx;
			background-color: #fff;
			border-radius: 30rpx;
			display: grid;
			grid-template-columns: auto 160px;
			grid-column-gap: 10rpx;
			align-items: center;

			.image {
				width: 100%;
				height: 250rpx;
				border-radius: 20rpx;
			}

			.from {
				color: #989898;
				font-size: 28rpx;
				margin-top: 40rpx;

				.mark {
					color: #FFAC2A;
					margin-left: 40rpx;
				}
			}
		}

		.info,
		.address,
		.menu,
		.code_box {
			padding: 40rpx;
			background-color: #fff;
			border-radius: 30rpx;

			.code {
				padding: 13rpx 43rpx;
				background-color: #F5F6F7;
				border-radius: 10rpx;
				color: #626667;
				font-size: 28rpx;
				text-align: center;
				margin: 0 auto 30rpx;
				width: 335rpx;
				box-sizing: border-box;

				.code_num {
					margin-left: 16rpx;
					color: #141414;
					font-weight: bold;
				}
			}

			.code_image {
				width: 336rpx;
				height: 336rpx;
				display: block;
				margin: 0 auto 30rpx;
			}
		}

		.info_item {
			padding: 40rpx 0;
			border-bottom: 2rpx solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.item_left {
				color: #818181;
				font-size: 30rpx;
			}

			.item_right {
				font-size: 30rpx;
				color: #231916;
			}
		}

		.info_item:last-child {
			border-bottom: none;
		}

		.address {
			display: grid;
			grid-template-columns: 70px auto;
			grid-column-gap: 20rpx;

			.item_left {
				color: #818181;
				font-size: 30rpx;
			}
		}

		.menu-list {
			// padding-bottom: 40rpx;
			// border-bottom: 2rpx solid #EEEEEE;

			.menu_item {
				margin-bottom: 40rpx;
				display: grid;
				grid-template-columns: 80rpx auto 40rpx auto;
				grid-column-gap: 20rpx;
				align-items: center;

				image {
					width: 100%;
					height: 80rpx;
					border-radius: 14rpx;
				}

				.num {
					color: #231916;
					font-size: 26rpx;
					text-align: center;
				}

				.original {
					color: #B1B1B1;
					font-size: 26rpx;
					text-decoration: line-through;
				}

				.current {
					color: #FC4A31;
					font-size: 30rpx;
					text-align: right;
				}
			}

			.menu_item:last-child {
				margin-bottom: 0;
			}
		}

		.menu_label {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 40rpx;
		}

		.menu_label:last-child {
			margin-bottom: 0;
		}

		.footer {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #fff;
			border-top-left-radius: 35rpx;
			border-top-right-radius: 35rpx;
			box-sizing: border-box;

			.btn1 {
				padding: 20rpx 30rpx;
				// display: grid;
				// grid-template-columns: 0.8fr 1fr;
				// grid-column-gap: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			.btn2 {
				padding: 40rpx 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

	}
</style>
